﻿@using DTcms.Model;
@using DTcms.Common;
@using System.Data;
@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutList.cshtml";
    ViewBag.Title = "站点数据备份";
    DataTable list = ViewData["list"] as DataTable;
}
@section HeaderContent{
   <script>
      function getQueryParam() {
         var keywords = $("#txtKeywords").val();
         var pagesize = $("#txtPageNum").val();
         return "channel_id=@ViewBag.ChannelId&keywords=" + keywords + "&pagesize=" + pagesize;
      }
      //查询数据
      function search() {
         document.location = "index?" + getQueryParam();
      }


      //ExePostBack回调函数
      function __doPostBack() {
         if (objId == "btnDelete") {
            submitdelete();
         }
      }

      function export_site() {
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        var site_id = 0;
        $($row).each(function (i, item) {
          if ($(item).find("input:checkbox").prop("checked")) {
            var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
            var obj = { id: id };
            json.list.push(obj);
            site_id = id;
          }
        });

        $.ajax({
          url: "/plugins/sitebackup/ajax.ashx?action=site_export&site=" + site_id + "&" + getQueryParam(),
          type: "POST",
          dataType: "html",
          data: "json=" + JSON.stringify(json),
          success: function (data) {
            var result = JSON.parse(data);
            alert(result["msg"]);
          },
          error: function () {
            alert("导出站点失败!");
          }
        });
      }

      function import_site() {
        var $row = $("#ltable tr:gt(0)");
        var json = { list: [] };
        var site_id = 0;
        $($row).each(function (i, item) {
          if ($(item).find("input:checkbox").prop("checked")) {
            var id = $(item).find("td:eq(0)").find("label:eq(0)").text();
            var obj = { id: id };
            json.list.push(obj);
            site_id = id;
          }
        });

        $.ajax({
          url: "/plugins/sitebackup/ajax.ashx?action=site_import&site=" + site_id + "&" + getQueryParam(),
          type: "POST",
          dataType: "html",
          data: "json=" + JSON.stringify(json),
          success: function (data) {
            var result = JSON.parse(data);
            alert(result["msg"]);
          },
          error: function () {
            alert("导入站点失败!");
          }
        });
      }
   </script>
}

<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="../../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>站点管理</span>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
        <ul class="icon-list">
          <li><a href="javascript:;" onclick="export_site();"><i class="iconfont icon-delete"></i><span>导出</span></a></li>
          <li><a href="javascript:;" onclick="import_site();"><i class="iconfont icon-delete"></i><span>导入</span></a></li>
        </ul>
      </div>
      <div class="r-list">
         <input type="text" id="txtKeywords" class="keyword" value="@ViewBag.Keywords" />
         <a href="javascript:search();" id="lbtnSearch" class="btn-search"><i class="iconfont icon-search"></i></a>
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->

<!--列表-->
<div class="table-container">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="ltable">
    <tr>
      <th width="6%">选择</th>
      <th align="left" width="15%">目录名</th>
      <th align="left" width="18%">标题</th>
      <th align="left">绑定域名</th>
      <th align="left" width="10%">排序</th>
      <th width="8%">源数据</th>
      <th width="8%">默认站</th>
      <th width="10%">操作</th>
    </tr>
     @foreach (DataRow row in list.Rows) {
       <tr>
         <td align="center">
           <span class="checkall" style="vertical-align:middle;">
                 <input type="checkbox" />
           </span>
           <label style="display:none">@row["id"]</label>
         </td>
         <td>@row["build_path"]</td>
         <td>@row["title"]</td>
         <td>
            @(row["domain"].ToString() == "" ? "-" : row["domain"].ToString())
         </td>
         <td>
            <input type="text" value="@row["sort_id"]" class="sort" onkeydown="return checkNumber(event);" />
         </td>
         <td align="center">
            @(Convert.ToInt32(row["parent_id"]) == 0 ? "√" : "×")
         </td>
         <td align="center">
            @(Convert.ToInt32(row["is_default"]) == 1 ? "√" : "×")
         </td>
         <td align="center"><a href="../site_edit/index?action=@DTEnums.ActionEnum.Edit&id=@row["id"]">修改</a></td>
       </tr>        
     }
     @if (list.Rows.Count == 0) {
        @Html.Raw("<tr><td align=\"center\" colspan=\"8\">暂无记录</td></tr>");
     }
  </table>
</div>
<!--/列表-->

<!--内容底部-->
<div class="line20"></div>
<div class="pagelist">
  <div class="l-btns">
    <span>显示</span>
     <input type="text" id="pagenum" class="pagenum" value="@ViewBag.PageSize" onkeydown="return checkNumber(event);" onchange="javascript:search();" />
    <span>条/页</span>
  </div>
  <div class="default">@Html.Raw(ViewBag.PageContent)</div>
</div>
<!--/内容底部-->